package cn.itsource.itsource.service.impl;

import cn.itsource.itsource.domain.Employee;
import cn.itsource.itsource.util.AjaxResult;
import cn.itsource.itsource.util.PageList;
import cn.itsource.itsource.query.EmployeeQuery;
import cn.itsource.itsource.mapper.EmployeeMapper;
import cn.itsource.itsource.service.IEmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public AjaxResult pageList(EmployeeQuery query) {
        //现在先实现最简单的分页
        //1.开启分页 pagehelper
        PageHelper.startPage(query.getCurrPage(),query.getPageSize());
        //2 调用查询所有的查询语句
        PageInfo<Employee> pageInfo=new PageInfo<>(employeeMapper.findAll(query));
        //3 封装数据并返回结果
        PageList pageList=new PageList(pageInfo.getTotal(),pageInfo.getList());
        AjaxResult ajaxResult= AjaxResult.success("查询成功");
        ajaxResult.setData(pageList);

        return ajaxResult;
    }

    @Override
    public AjaxResult saveOrUpdate(Employee emp) {
        employeeMapper.save(emp);

        return AjaxResult.success("操作成功");

    }
}
